<style lang="less">
@import '../../../styles/common.less';
</style>

<template>
    <Card style="height:800px">
        <Card>
            <header>
                <Form action="" method="get" name="exportList" id="exportList" enctype="multipart/form-data">
                    <span>日期：</span>
                    <DatePicker v-model="pushCondition.pushBeginDate" type="date" style="width: 150px" name="pushBeginDate" value="yyyy-MM-dd"></DatePicker>
                    <span>至</span>
                    <DatePicker v-model="pushCondition.pushEndDate" type="date" placement="bottom-end" style="width: 150px" name="pushEndDate" value="yyyy-MM-dd"></DatePicker>
                    <span style="width: 200px;margin-left: 20px;" >状态：</span>
                    <Select v-model="pushCondition.pushStatus" class="v-select-wrapper" style="width:150px" name="pushStatus">
                        <Option v-for="item in statusList" :value="item.key" :key="item.key">{{ item.label }}</Option>
                    </Select>
                    <Button type="primary" @click="listQuery"  style="margin-left: 20px;">查询</Button>
                    <input type="hidden" name="pageNum" id="pageNum" value="" />
                    <input type="hidden" name="pageSize" id="pageSize" value="" />
                </Form>
            </header>
        </Card>
        <Form action="" method="get" name="exportListFile" id="exportListFile" enctype="multipart/form-data">
            <input id="id" name="id" type="hidden" />
            <input id="fileName" name="fileName" type="hidden" />
        </Form>
        <Card>
            <div>
                <Table border :columns="orderColumns" :data="orderData" style="width: 100%;"></Table>
            </div>
            <div style="text-align: center;margin-top: 36px;">
                <Page :total="pushCondition.total" :current="pushCondition.pageNum" :page-size="pushCondition.pageSize" size="small" show-elevator show-sizer show-total @on-change="pageChange" @on-page-size-change="sizeChange"></Page>
            </div>
            <div style="margin-top: 93px;text-align: center;">
                <Button type="primary" @click="downLoad">下载</Button>
            </div>
        </Card>
    </Card>
</template>

<script>
export default {
  name: 'mutative-router',
  data () {
    return {
      pushCondition: {
        pushBeginDate: '',
        pushEndDate: '',
        pushStatus: '',
        pageNum: 1,
        pageSize: 10,
        total: 0,
        id: '',
        fileName: ''
      },
      orderColumns: [
        {
          type: 'index',
          title: '序号',
          width: 60
        },
        {
          title: '还款笔数',
          key: 'count',
          align: 'center'
        },
        {
          title: '还款金额',
          key: 'amt',
          align: 'center'
        },
        {
          title: '应还款客户明细',
          key: 'fileName',
          align: 'center',
          render: (h, params) => {
            return h('span', {
              style: {
                'color': '#20a0ff',
                'cursor': 'pointer'
              },
              on: {
                click: () => {
                  var vm = this
                  document.getElementById('exportListFile').action = this.$appContext.marvels_core_financial + 'financial/fund/mtRepayPush/service/downLoadFile'
                  document.getElementById('id').value = params.row.id
                  document.getElementById('fileName').value = params.row.fileName
                  document.getElementById('exportListFile').submit()
                  vm.listQuery()
                }
              }
            }, params.row.fileName)
          }
        },
        {
          title: '推送文件',
          key: 'pushFile',
          align: 'center',
          render: (h, params) => {
            return h('span', {
              style: {
                'color': '#20a0ff',
                'cursor': 'pointer'
              },
              on: {
                click: () => {
                  var vm = this
                  document.getElementById('exportListFile').action = this.$appContext.marvels_core_financial + 'financial/fund/mtRepayPush/service/downLoadFile'
                  document.getElementById('id').value = params.row.id
                  document.getElementById('fileName').value = params.row.pushFile
                  document.getElementById('exportListFile').submit()
                  vm.listQuery()
                }
              }
            }, params.row.pushFile)
          }
        },
        {
          title: '推送时间',
          key: 'pushTime',
          align: 'center',
          render: (h, params) => {
            var vm = this
            return h('div', [
              h('span', vm.$util.loanModularFormatTime(params.row.pushTime))
            ])
          }
        },
        {
          title: '推送结果',
          key: 'status',
          align: 'center'
        },
        {
          title: '操作',
          align: 'center',
          render: (h, params) => {
            if (params.row.status === '失败' && params.row.judge) {
              return h('span', {
                style: {
                  'color': '#20a0ff',
                  'cursor': 'pointer'
                },
                on: {
                  click: () => {
                    var vm = this
                    vm.sendData(params.row.fileName)
                  }
                }
              }, '重新推送')
            }
          }
        }
      ],
      orderData: [],
      statusList: [
        {
          'key': '',
          'label': '请选择'
        },
        {
          'key': '0',
          'label': '成功'
        },
        {
          'key': '1',
          'label': '失败'
        },
        {
          'key': '2',
          'label': '未推送'
        }
      ]
    }
  },
  computed: {
    avatorImage () {
      return localStorage.avatorImgPath
    }
  },

  created () {
    // 初始化当前页面请求对象实例
    this.$ajax = this.$util.ajax()
    this.listQuery()
  },

  methods: {
    pageChange: function (pageNum) {
      var vm = this
      vm.pushCondition.pageNum = pageNum
      vm.listQuery()
    },
    sizeChange: function (pageLength) {
      var vm = this
      vm.pushCondition.pageSize = pageLength
      vm.listQuery()
    },
    listQuery () {
      var vm = this
      this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/fund/mtRepayPush/service/pushList', vm.pushCondition).then(re => {
        var data = re.data
        vm.orderData = data.data.object
        vm.pushCondition.total = data.data.total
      }).catch(er => {

      })
    },
    downLoad () {
      document.getElementById('exportList').action = this.$appContext.marvels_core_financial + 'financial/fund/mtRepayPush/service/downLoad'
      document.getElementById('pageNum').value = this.pushCondition.pageNum
      document.getElementById('pageSize').value = this.pushCondition.pageSize
      document.getElementById('exportList').submit()
    },
    sendData (fileName) {
      var vm = this
      vm.pushCondition.fileName = fileName
      this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/fund/mtRepayPush/service/pushData', vm.pushCondition).then(re => {
        var data = re.data
        var message = data.message
        this.$Message.warning(message)
        vm.listQuery()
      }).catch(er => {

      })
    }

  }
}
</script>
